﻿using System;
using System.IO;
using System.Text;
using System.Collections.Generic;

namespace Poi.NET.poifs.storage
{
    /**
     * Abstract base class of all POIFS block storage classes. All
     * extensions of BigBlock should write 512 bytes of data when
     * requested to write their data.
     *
     * This class has package scope, as there is no reason at this time to
     * make the class public.
     *
     * @author Marc Johnson (mjohnson at apache dot org)
     * Adapted by Josh Fornwall
     */

    abstract class BigBlock : BlockWritable
    {

        /**
         * Default implementation of write for extending classes that
         * contain their data in a simple array of bytes.
         *
         * @param stream the OutputStream to which the data should be
         *               written.
         * @param data the byte array of to be written.
         *
         * @exception IOException on problems writing to the specified
         *            stream.
         */

        protected void doWriteData(Stream stream, byte[] data)
        {
            stream.Write(data, 0, data.Length);
        }

        /**
         * Write the block's data to an OutputStream
         *
         * @param stream the OutputStream to which the stored data should
         *               be written
         *
         * @exception IOException on problems writing to the specified
         *            stream
         */

        abstract void writeData(Stream stream);

        /* ********** START implementation of BlockWritable ********** */

        /**
         * Write the storage to an OutputStream
         *
         * @param stream the OutputStream to which the stored data should
         *               be written
         *
         * @exception IOException on problems writing to the specified
         *            stream
         */

        public void writeBlocks(Stream stream)
        {
            writeData(stream);
        }

        /* **********  END  implementation of BlockWritable ********** */
    }   // end abstract class BigBlock
}
